<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">发送短信统计</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"
                                         rendered="#{security:areAllGranted('SMS_STATISTIS_SEARCH')}"/>
                        <p:columnToggler datasource="smsStatisticsDataTable" trigger="toggler"
                                         rendered="#{security:areAllGranted('SMS_STATISTIS_SEARCH')}"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{smsStatisticsBean.isNormal() and security:areAllGranted('SMS_STATISTIS_SEARCH')}"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{smsStatisticsBean.onReset}"
                                         process="@this"
                                         update="@form" rendered="#{smsStatisticsBean.isNormal()}"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         action="#{smsStatisticsBean.exportExcel()}"
                                         rendered="#{smsStatisticsBean.isNormal() and security:areAllGranted('SMS_STATISTIS_EXPORT')}"
                                         ajax="false" />
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"></p:button>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card ui-g-12">

                            <div class="ui-g-1">
                                <p:outputLabel value="短链接"/>
                            </div>
                            <div class="ui-g-5">
                                <p:inputText value="#{smsStatisticsBean.$.shortLink}"/>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="执行时间"/>
                            </div>
                            <div class="ui-g-5">
                                <p:calendar value="#{smsStatisticsBean.$.startDate}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"/>
                                <span>—</span>
                                <p:calendar value="#{smsStatisticsBean.$.endDate}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"/>
                            </div>
                        </div>

                        <div class="card">
                            <p:dataTable id="smsStatisticsDataTable"
                                         style="width: 100%"
                                         var="record"
                                         value="#{smsStatisticsBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{smsStatisticsBean.selectedRecords}"
                                         resizableColumns="true"
                                         rendered="#{security:areAllGranted('SMS_STATISTIS_SEARCH')}">

                                <p:column headerText="发送任务" style="width: 100px">
                                    展开
                                    <p:spacer width="20" height="20"/>
                                    <p:rowToggler rendered="#{true}"/>
                                </p:column>

                                <p:column headerText="执行时间">
                                    <h:outputText value="#{record.executeTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>

                                <p:column headerText="短链接" style="width: 350px">
                                    <h:outputText value="#{record.shortLink}"/>
                                </p:column>

                                <p:column headerText="发送数">
                                    <h:outputText value="#{record.sendCount}"/>
                                </p:column>

                                <p:column headerText="到达数">
                                    -
                                </p:column>

                                <p:column headerText="点击数">
                                    <h:outputText value="#{record.clickCount}"/>
                                </p:column>

                                <p:column headerText="H5登记数">
                                    <h:outputText value="#{record.h5RegistrationCount}"/>
                                </p:column>

                                <p:column headerText="H5注册数">
                                    <h:outputText value="#{record.h5RegisterCount}"/>
                                </p:column>

                                <p:column headerText="登录数">
                                    <h:outputText value="#{record.loginCount}"/>
                                </p:column>

                                <p:column headerText="注册数">
                                    <h:outputText value="#{record.registerCount}"/>
                                </p:column>

                                <p:rowExpansion>
                                    <p:dataTable
                                            lazy="true"
                                            value="#{record.sendTasks}"
                                            style="width: 100%" var="task">
                                        <p:column headerText="发送任务ID">
                                            <h:outputText value="#{task.id}"/>
                                        </p:column>
                                        <p:column headerText="名称">
                                            <h:outputText value="#{task.name}"/>
                                        </p:column>
                                        <p:column headerText="发送文案"  style="width: 700px">
                                            <h:outputText value="#{task.content}"/>
                                        </p:column>
                                        <p:column headerText="发送通道">
                                            <h:outputText value="#{smsStatisticsBean.translate(DictionaryCode.SMS_PLATFORM_CHANNEL,task.platformChannel)}"/>
                                        </p:column>
                                        <p:column headerText="短信数量">
                                            <h:outputText value="#{task.sendCount}"/>
                                        </p:column>
                                    </p:dataTable>
                                </p:rowExpansion>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
